/* **********************************************************************************
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
* This source code is subject to terms and conditions of the Shared Source License
* for DSL Editor PowerToy. A copy of the license can be found in the License.htm file
* at the root of this distribution. If you can not locate the Shared Source License
* for DSL Editor PowerToy, please obtain a copy from: http://www.codeplex.com/dsltreegrideditor/Project/License.aspx.
* By using this source code in any fashion, you are agreeing to be bound by
* the terms of the Shared Source License for DSL Editor PowerToy.
*
* You must not remove this notice, or any other, from this software.
*
* **********************************************************************************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;

using Microsoft.VisualStudio.Modeling;
using Microsoft.VisualStudio.Modeling.Design;

namespace DslEditorPowerToy.Languages.EditorConfiguration
{
    /// <summary>
    /// Shared description provider
    /// </summary>
    internal class EditorConfigurationDescriptionProvider : ElementTypeDescriptionProvider
    {
        #region Public Methods
        protected override ElementTypeDescriptor CreateTypeDescriptor(ICustomTypeDescriptor parent, ModelElement element)
        {
            //Return our shared type descriptor
            return new EditorConfigurationTypeDescriptor(parent, element);
        }
        #endregion
    }
    /// <summary>
    /// SHared type descriptor
    /// </summary>
    internal class EditorConfigurationTypeDescriptor : ElementTypeDescriptor
    {
        #region Constructors
        public EditorConfigurationTypeDescriptor(ICustomTypeDescriptor parent, ModelElement element)
            : base(parent, element)
        {
        }
        #endregion

        #region Public Methods
        public override PropertyDescriptorCollection GetProperties()
        {
            return this.GetProperties(null);
        }
        /// <summary>
        /// Filter avaialbes descriptors based on state of element
        /// </summary>
        /// <param name="attributes"></param>
        /// <returns></returns>
        public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            PropertyDescriptorCollection descriptors = base.GetProperties(attributes);

            //Filter appropriate properties
            if (this.ModelElement is DslDomain)
            {
                DslDomain domain = this.ModelElement as DslDomain;

                //Check value of properties
                if (EditorHostStyle.ToolWindow != domain.HostingStyle)
                {
                    //Remove descriptors for other properties
                    ComponentModelHelper.RemoveAllDescriptorsBut(descriptors, 
                        new string[] {"HostingStyle", "NavigationStyle"});
                }
            }

            return descriptors;
        }
        #endregion
    }
}
